﻿using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebReports
{
    public partial class ReportView: System.Web.UI.Page
    {
        private int devType = 0;
        private string reportName = "";
        private int devId = 0;
 
        protected void Page_Load(object sender, EventArgs e)
        {
             // 页面加载时的处理

            devType = Convert.ToInt32(this.Context.Request["devtype"]);
            if (string.IsNullOrEmpty(Context.Request["report"]) == false)
            {
                reportName = this.Context.Request["report"].ToString();
            }
            if (string.IsNullOrEmpty(Context.Request["td_id"]) == false)
            {
                devId = Convert.ToInt32(this.Context.Request["td_id"]);
            }

            if (!IsPostBack)
            {
                this.Time.Text = (System.DateTime.Now.ToString("yyyy-MM-dd"));
    
                LoadReport();
            }
        }

        
        protected void BTN_REPORTVIEW_Click1(object sender, EventArgs e)
        {
            LoadReport(); 
        }

        protected void LoadReport()
        {


            RV_REPORT.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            RV_REPORT.ShowCredentialPrompts = true;
            ReportServerCredentials rpCredential = new ReportServerCredentials();
            RV_REPORT.ServerReport.ReportServerCredentials = rpCredential;
            RV_REPORT.ServerReport.ReportServerUrl = new Uri("http://localhost:9200/ReportServer");

            switch (reportName)
            {
                case "T1_Internal_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T1_REGULATING_DEVICE_STATS_REPORT/T1_Internal_Stats_Report";
                    break;
                case "T1_External_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T1_REGULATING_DEVICE_STATS_REPORT/T1_External_Stats_Report";
                    break;
                case "T1_Power_Quality_Stats_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T1_REGULATING_DEVICE_STATS_REPORT/T1_Power_Quality_Stats_Trends_Report";
                    break;
                case "T1_Power_Quality_Equipment_Operation_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T1_REGULATING_DEVICE_STATS_REPORT/T1_Power_Quality_Equipment_Operation_Stats_Report";
                    break;
              //以上为类型一
                case "T2_Internal_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Internal_Stats_Report";
                    break;
                case "T2_External_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_External_Stats_Report";
                    break;
                case "T2_Power_And_Energy_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Power_And_Energy_Report";
                    break;
                case "T2_Harmonics_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Harmonics_Report";
                    break;
                case "T2_Equipment_Operating_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Equipment_Operating_Trends_Report";
                    break;
                case "T2_Child_Equipment_Operation_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Child_Equipment_Operation_Report";
                    break;
                case "T2_Equipment_Failure_Information_Summary_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T2_PASSIVE_COMPENSATION_AND_HARMONIC_CONTROL_DEVICES_REPORT/T2_Equipment_Failure_Information_Summary_Report";
                    break;
                //以上为类型二
                case "T3_Internal_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T3_APF_POWER_QUALITY_STATS_REPORT/T3_Internal_Stats_Report";
                    break;
                case "T3_External_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T3_APF_POWER_QUALITY_STATS_REPORT/T3_External_Stats_Report";
                    break;
                case "T3_Power_Quality_Stats_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T3_APF_POWER_QUALITY_STATS_REPORT/T3_Power_Quality_Stats_Trends_Report";
                    break;
                case "T3_Power_Quality_Equipment_Operation_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T3_APF_POWER_QUALITY_STATS_REPORT/T3_Power_Quality_Equipment_Operation_Stats_Report";
                    break;
                //以上为类型三
                case "T4_Internal_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Internal_Stats_Report";
                    break;
                case "T4_External_Stats_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_External_Stats_Report";
                    break;
                case "T4_Power_And_Energy_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Power_And_Energy_Report";
                    break;
                case "T4_Harmonics_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Harmonics_Report";
                    break;
                case "T4_Equipment_Operating_Trends_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Equipment_Operating_Trends_Report";
                    break;
                case "T4_Child_Equipment_Operation_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Child_Equipment_Operation_Report";
                    break;
                case "T4_Equipment_Failure_Information_Summary_Report":
                    RV_REPORT.ServerReport.ReportPath = "/JSTTReport/Online_Reports/T4_INTEGRATED_POWER_DISTRIBUTION_UNIT_REPORT/T4_Equipment_Failure_Information_Summary_Report";
                    break;
                default:
                    return;
                //以上为类型四
            }


            
            //if (RV_REPORT.Height)
            //{

            //}

     

            DateTime dt=new DateTime() ;
            if (Time.Text != "")
            {
                dt = Convert.ToDateTime(Time.Text);
            }



            ReportParameter[] p = new ReportParameter[4];
        
            p[0] = new ReportParameter("year", Convert.ToString(dt.Year));
            p[1] = new ReportParameter("month", Convert.ToString(string.Format("{0,2:00}",dt.Month)));
            p[2] = new ReportParameter("day", Convert.ToString(dt.Day));
            p[3] = new ReportParameter("devtype", devId.ToString());
            RV_REPORT.ServerReport.SetParameters(p);

            RV_REPORT.ShowParameterPrompts = false;
            RV_REPORT.ServerReport.Refresh();
        }

        protected void Time_TextChanged(object sender, EventArgs e)
        {
            
        }



    }
}